package com.springboot.study.tests.nio;

import java.net.InetSocketAddress;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;

/**
 * @Author: guodong
 * @Date: 2020/12/14 11:39
 * @Version: 1.0
 * @Description:
 */
public class NIOClient {

    public static void main(String[] args) throws Exception{
        SocketChannel socketChannel = SocketChannel.open();
        socketChannel.configureBlocking(false);

        boolean connected = socketChannel.connect(new InetSocketAddress("localhost", 8080));


        // Selector（选择器）是Java NIO中能够检测一到多个NIO通道，并能够知晓通道是否为诸如读写事件做好准备的组件。
        // 这样，一个单独的线程可以管理多个channel，从而管理多个网络连接。

        Selector selector = Selector.open();


        socketChannel.register(selector, SelectionKey.OP_READ);





    }



}
